import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver

# 用户管理
class UserManagement:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/user"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetUserManagement(self):
        # 筛选机构
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/div[2]/div/div[3]/div/div/div/div/span[4]/span[2]').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/div[2]/div/div[3]/div/div/div/div/span[4]/span[2]').click()

        # 按照姓名搜索
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("张三")
        # 点击搜索
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(0.5)
        # 截图查看
        QESDriver.GetScreenShot()
        # 点击重置
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()

        ################################################################
    def CreateNewUsers(self):
        # 新建
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[1]/button').click()
        # 输入用户名：测试新建用户
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("测试新建用户")
        # 输入登录名：hellobit
        self.driver.find_element(By.XPATH,'//*[@id="username"]').send_keys("hellobit")
        # 输入密码：123456
        self.driver.find_element(By.XPATH,'//*[@id="password"]').send_keys("123456")
        # 输入确认密码：123456
        self.driver.find_element(By.XPATH,'//*[@id="rePassword"]').send_keys("123456")
        QESDriver.GetScreenShot()
        # 点击确定
        # self.driver.find_element(By.XPATH,'/html/body/div[7]/div/div[3]/div/div/div[3]/div/div/div[2]/button').click()
        self.driver.refresh()
        # 批量导入
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[2]/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # self.driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div/div[2]/div[3]/button[1]').click()
        self.driver.refresh()
        # 编辑用户
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[8]/div/div[1]/a').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # self.driver.find_element(By.XPATH, '/html/body/div[7]/div/div[3]/div/div/div[3]/div/div/div[1]/button').click()
        self.driver.refresh()

# 角色管理
class RoleManagement:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/role"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetRoleManagement(self):
        # 查询
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("user")
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(0.5)
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()

        # 新建
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        # 输入角色信息
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("test")
        # 输入角色编码
        self.driver.find_element(By.XPATH,'//*[@id="code"]').send_keys("745300")
        # 输入描述
        self.driver.find_element(By.XPATH,'//*[@id="remark"]').send_keys("测试新建角色")
        QESDriver.GetScreenShot()
        self.driver.refresh()

        # 编辑角色
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[6]/div/div[1]/a').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()

# 组织机构
class InstitutionalFramework:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/dept"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetInstitutionalFramework(self):
        # 新建操作
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div/div/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 编辑操作
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div/div/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[4]/div/div[1]/a').click()
        QESDriver.GetScreenShot()
        self.driver.refresh()

# 岗位设置
class PostSetting:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/position"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetPostSetting(self):
        # 输入查询
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("aaa")
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()
        # 新建岗位
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        # 输入岗位名称
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("测试新建岗位")
        # 输入岗位编码
        self.driver.find_element(By.XPATH,'//*[@id="code"]').send_keys("745300")
        self.driver.refresh()
        # 编辑岗位
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[4]/div/div[1]/a').click()
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 删除岗位
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[4]/div/div[2]/a').click()
        time.sleep(0.5)
        self.driver.refresh()

# 字典设置
class Dictionarization:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/dict"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetDictionarization(self):
        # 输入查询
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("aaa")
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()
        # 新建字典
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        # 输入字典名称
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("cccc")
        # 输入字典编码
        self.driver.find_element(By.XPATH,'//*[@id="code"]').send_keys("745300")
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 字典项
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[6]/div/div[1]/a').click()
        QESDriver.GetScreenShot()
        self.driver.refresh()

# 个人设置
class PersonalSettings:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/setting"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetPersonalSettings(self):
        # 清空原有的姓名
        QESDriver.ClearInput(self.driver.find_element(By.XPATH,'//*[@id="name"]'))
        # 输入新的
        self.driver.find_element(By.XPATH,'//*[@id="name"]').send_keys("小小王")
        # 查找输入手机号
        self.driver.find_element(By.XPATH,'//*[@id="phone"]').send_keys("19290061455")
        # 查找输入邮箱
        self.driver.find_element(By.XPATH,'//*[@id="email"]').send_keys("3446066695@qq.com")
        # 查找输入个人简介
        self.driver.find_element(By.XPATH,'//*[@id="profile"]').send_keys("无个人简介")
        QESDriver.GetScreenShot()
        # 点击提交
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div/div/div[2]/div[2]/div[1]/form/div[5]/div[2]/button').click()
        # 点击安全设置
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div/div/div[1]/ul/li[2]/span').click()
        QESDriver.GetScreenShot()
        # 点击系统设置
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div/div/div[1]/ul/li[3]/span').click()
        QESDriver.GetScreenShot()
